package com.ruoyi.web.controller.aggregation;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.aggregation.Proportion;
import com.ruoyi.system.service.aggregation.IProportionService;

/**
 * 分佣比例Controller
 * 
 * @author ruoyi
 * @date 2025-01-01
 */
@RestController
@RequestMapping("/agg/proportion")
public class ProportionController
{
    @Autowired
    private IProportionService proportionService;

    /**
     * 查询分佣比例配置
     */
    @GetMapping("/getInfo")
    public AjaxResult getInfo()
    {
        try
        {
            Proportion query = new Proportion();
            List<Proportion> list = proportionService.selectProportionList(query);
            return AjaxResult.success(list);
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 添加分佣比例配置
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Proportion proportion)
    {
        try
        {
            proportionService.insertProportion(proportion);
            return AjaxResult.success();
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 修改分佣比例配置
     */
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Proportion proportion)
    {
        try
        {
            proportionService.updateProportion(proportion);
            return AjaxResult.success();
        }
        catch (Exception e)
        {
            return AjaxResult.error(e.getMessage());
        }
    }
}

